#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stdarg.h>
main(int argc, char *argv[])
{
   FILE *fp,*fp0,*fp1,*fp2,*fp3;
   int i;
   char *p;
   char temp[90],temp0[90],temp1[90],temp2[90],cxfn[15],asafn[15],volfn[15],dis_atom[7],datafn[15],head[90];
   float cx,asa,asaar,ruf,vol;
   for(i=0;i<15;i++)
	   {
	   cxfn[i]='\0';
	   asafn[i]='\0';
	   datafn[i]='\0';
	   volfn[i]='\0';
	   }
   fp=fopen(argv[1],"r");
   if(fp==NULL)
	   {
	    puts("please input an roughness file name such as:1a4iA.ruf.ent");
        return 1;
	   }
   strncpy(cxfn,argv[1],5);
   strcat(cxfn,".cx");
   strncpy(asafn,argv[1],5);
   strcat(asafn,".asa");
   strncpy(volfn,argv[1],5);
   strcat(volfn,".vol");
   strncpy(datafn,argv[1],5);
   strcat(datafn,".data");
   printf("Processing:%s,%s,%s,%s\n",cxfn,asafn,datafn,volfn);
   fp0=fopen(cxfn,"r");
   fp1=fopen(asafn,"r");
   fp2=fopen(volfn,"r");
   fp3=fopen(datafn,"w");  
   while(!feof(fp))
	   {
	   fgets(temp,90,fp);
       strncpy(dis_atom,temp,6);dis_atom[6]='\0';
       if(strcmp(dis_atom,"ATOM  ")==0)
		   {
    	   fgets(temp0,90,fp0);
           fgets(temp1,90,fp1);
           fgets(temp2,90,fp2);
           p=&temp0[62];
           cx=atof(p);  //cx value of each atom
           p=&temp1[56];
           asa=atof(p); //asa value of each atom
           p=&temp1[64];
           asaar=atof(p);//Atom radius
           p=&temp[62];
           ruf=atof(p); //roughness value
           p=&temp2[62];
           vol=atof(p); //vol value
           fprintf(fp3,"%c%6.2f%6.2f%6.2f%6.2f%6.2f%5c\n",temp[77],cx,asa,asaar,ruf,vol,temp2[82]);
           }
       }
   fclose(fp);
   fclose(fp0);
   fclose(fp1);
   fclose(fp2);
   fclose(fp3);
   return 0;
}
